package boc.sx.gateway.socket.server.initializer;

import boc.sx.gateway.protocal.DefaultCodec;
import boc.sx.gateway.socket.server.handler.SimpleServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;

import java.nio.charset.StandardCharsets;

public class SimpleServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(1163023952, 3, 4, 0, 0));
        // in
        ch.pipeline().addLast(new DefaultCodec());
        ch.pipeline().addLast(new StringDecoder(StandardCharsets.UTF_8));

        // out
//        ch.pipeline().addLast(new StringEncoder(StandardCharsets.UTF_8));
        ch.pipeline().addLast(new SimpleServerHandler());
    }
}
